require('Collider')
require('Glow')
require('Swirly')
require('Collider')
require('Player')
require('EventHandler')
require('Star')
require('Collectible')
require('Parasite')
require('BlackHole')

World = {}
World.__index = World
parasiteSpeed = 4
function World.load(width,height)
        
        local world = {}
        setmetatable(world, World)
        
        --SCREEN ATTRIBUTES
        world.screenX = 1200
        world.screenY = 800
        
        
        --BASIC WORLD ATTRIBUTES
        world.width = width
        world.height = height
        world.glow = Glow.load(600,400)
        world.player = Player.load(world)
        --world.collect = Collectible.load(400, 100)
        world.collectibleList = {}
        world.starList = {}
        world.staticStarList = {}
        world.scrnXOffset = width/2
        world.scrnYOffset = height/2
        world.debugText = ""
        world.parasiteList = {}
        --OBJECT GENERATION
        world.swirlyList = {}
		
		--BLACK HOLE GENERATION
		world.totalBlackHoles = 20
		world.blackHoleList = {}
		world:spawnBlackHoles()
        
        
        --COLLIDER CODE
        MyCollider.load(world)
        MyCollider.addPlayerCollider( world.player.x, world.player.y , world.player.radius)
        
        --we will need to figure out the radius for the glow
        MyCollider.addGlowCollider(world.glow.x ,world.glow.y , 175)
        
       
        --COLLECTIBLE GENERATION
        world.totalCollectibles = 100
		 --total parasites
		 world.totalParasites = 150
        --These lines represent distance from the center in pixels
        world.zoneEdges = {2000, 3500}
        --This represents current number of items in each zone
        world.itemsInZones = {0, 0, 0}
        --These represent percentage of total collectibles in each zone
        world.zonePercentages = {.15, .3, .55}
        --This represents border around the edge of the map that no collectibles will spawn in
        world.borderSize = 50
        --This spawns the collectibles
        world:spawnCollectibles()
        

        --STAR GENERATION
        --This holds the number of stars
        world.numStars = 1000
        --This holds the number of static stars
        world.numStaticStars = 10000
        --This spawns the stars
        world:spawnStars()
        --This spawns the static stars
        world:spawnStaticStars()
		 --This spawns parasites
		 world:spawnParasites()
       
        --EVENT HANDLER CODE
        --Leave this last
        world.eventHandler = EventHandler.load(world)
        
        return world
        
end

function World:update(dt)
		 
        self.debugText = ""
        for i, star in ipairs(self.starList) do
        
                star:update(dt)
                
        end
		
		self.eventHandler.movDist = 4
		
		for i, parasite in ipairs(self.parasiteList) do
		
			interParaDist = self.calcDist(parasite.x, parasite.y, self.player.x, self.player.y)
			if interParaDist < 50 then
				self.eventHandler.movDist = self.eventHandler.movDist - .5
			end
		    parasite:update(dt)
		
		end 

        glowPlayerDistance = self.calcDist(self.glow.x, self.glow.y, self.screenX/2, self.screenY/2)
        if glowPlayerDistance < 500 then
                --self.player.health = self.player.health - 1000/(math.pow(glowPlayerDistance, 2))
                self.glow.health = self.glow.health + 3
                
                --Calculate direction for particles
                w = self.glow.x - self.player.x
                h = self.glow.y - self.player.y
                
				toGlow = 0
                
                --Width is 0
                if (w == 0) then
                        if (h > 0) then
                                toGlow = math.pi/2
                        elseif (h < 0) then
                                toGlow = 3*math.pi/2
                        end
                --Height is 0
                elseif (h == 0) then
                        if (w > 0) then
                                toGlow = 0
                        elseif (w < 0) then
                                toGlow = math.pi
                        end
                --Both are negative
                elseif (self.glow.x > self.player.x) then
                        toGlow = math.atan(h/w)
                else
                        toGlow = math.pi-math.atan(-h/w)
                end
                self.player.particleSys:setDirection(toGlow)
                self.player.particleSys:setSpread(.5)
                self.player.particleSys:setTangentialAcceleration(0)
                self.player.particleSys:setRadialAcceleration(25+5000/glowPlayerDistance)
                self.player.particleSys:setParticleLife(2*(glowPlayerDistance/500))
                self.player.particleSys:setEmissionRate(200)
                self.player.particleSys:setColors(255, 255, 255, 255, 255, 128, 0, 0)

        end
        
        if glowPlayerDistance >= 500 then
		                --Calculate direction for particles
                w = self.glow.x - self.player.x
                h = self.glow.y - self.player.y
                
				toGlow = 0
                
                --Width is 0
                if (w == 0) then
                        if (h > 0) then
                                toGlow = math.pi/2
                        elseif (h < 0) then
                                toGlow = 3*math.pi/2
                        end
                --Height is 0
                elseif (h == 0) then
                        if (w > 0) then
                                toGlow = 0
                        elseif (w < 0) then
                                toGlow = math.pi
                        end
                --Both are negative
                elseif (self.glow.x > self.player.x) then
                        toGlow = math.atan(h/w)
                else
                        toGlow = math.pi-math.atan(-h/w)
                end
				
				self.player.particleSys:setDirection(toGlow)
                self.player.particleSys:setSpread(.25)
                self.player.particleSys:setTangentialAcceleration(1)
                self.player.particleSys:setRadialAcceleration(25+5000/glowPlayerDistance)
                self.player.particleSys:setParticleLife(2*(glowPlayerDistance-500)/7500)
                self.player.particleSys:setEmissionRate(200)
				glowHPPercentage = self.glow.health / 6000
				if glowHPPercentage > 1 then		
					glowHPPercentage = 1		
				end
				if glowPlayerDistance >= 850 then
					self.player.particleSys:setColors(255, 255, 255, 255, 255*(1-glowHPPercentage), 255*glowHPPercentage, 0, 0)
				end
				
                --[[self.player.particleSys:setDirection(0)
                self.player.particleSys:setSpread(360)
                self.player.particleSys:setTangentialAcceleration(-100)
                self.player.particleSys:setRadialAcceleration(-850)
                self.player.particleSys:setParticleLife(.3)
                self.player.particleSys:setEmissionRate(100)
                self.player.particleSys:setColors(255, 255, 255, 255, 255, 255, 255, 0)--]]
        end
        
		if self.player.isPulseActive == true then
			
			for i, parasite in ipairs(self.parasiteList) do
				dist = self.calcDist(parasite.x, parasite.y, 600, 400)
				
				if dist < 170 then
					--code to kill parasites goes here
					parasite.particleSys:setColors(0, 0, 0, 0, 0, 0, 0, 0)
					parasite.particleSys:stop()
					
					MyCollider.setParasiteToGhost(i)
					 
					parasite:die()
				end
			end
			
			self.player.pulseTimer = self.player.pulseTimer - 1
			self.player.particleSys = Particles.getShieldParticleSys(0,0)
			if self.player.pulseTimer == 0 then
				self.player.isPulseActive = false
				self.player.particleSys = Particles.getFuzzParticleSys(0,0)
			end
		end
		
        MyCollider.update(dt)
        self.glow:update(dt)
        self.player:update(dt)
        --self.collect:update(dt)
        for i, swirly in ipairs(self.swirlyList) do
                
                swirly:update(dt)
                
        end
        for i, collectible in ipairs(self.collectibleList) do
                        
                collectible:update(dt)
                        
        end

          if playerControl then
               self.eventHandler:update(dt, world)
          end
        
		if self.player.isPulseActive == false then
			self:checkBlackHoles()
		end
end

function World:draw()
    	 MyCollider.draw()
		 if TESTING == true then
			love.graphics.print(self.debugText, 5, 200)
		end
        --Initialize bounds check variable
        bc = false

        --Draw Dynamic Stars
        for i, star in ipairs(self.starList) do
                
                bc = self:boundsCheck(star.x, star.y)
                if bc == true then
                        star:draw()
                end
                bc = false
        
        end
        
        --Draw Static Stars
        for i=1, #self.staticStarList do
                
                bc = self:boundsCheck(self.staticStarList[i][1], self.staticStarList[i][2])
                if bc == true then
                        love.graphics.point(self.staticStarList[i][1], self.staticStarList[i][2])
                end
                bc = false
                
        end
		
		love.graphics.setBlendMode('alpha')
		
		--Draw Black Holes
		for i, blackHole in ipairs(self.blackHoleList) do
		
			bc = self:boundsCheck(blackHole.x, blackHole.y)
			if bc == true then
				blackHole:draw()
			end
			bc = false
			
		end

        --Draw Glow
        bc = self:boundsCheck(self.glow.x, self.glow.y)
        if bc == true then
                self.glow:draw()
        end
        bc = false
        
        --self.collect:draw()
        --Draw Swirlies 
        for i, swirly in ipairs(self.swirlyList) do
                
                bc = self:boundsCheck(swirly.x, swirly.y)
                if bc == true then
                        swirly:draw()
                end
                bc = false
                
        end
        
        --Draw Collectibles
        for i, collectible in ipairs(self.collectibleList) do
                       
                 bc = self:boundsCheck(collectible.x, collectible.y)
                 if bc == true then
                        collectible:draw()
                 end
                 bc = false
                        
        end
		
		 for i, parasite in ipairs(self.parasiteList) do
				    
					bc = self:boundsCheck(parasite.x, parasite.y)
				    if bc == true then                 
				    	parasite:draw()
				    end                 
		 end
		 
		 --TIMER PRINT CODE
		love.graphics.setColor(255, 255, 255, 255)
        love.graphics.setFont(menu.font_title)
		  
		love.graphics.printf(minOutput, 30, self.screenY - self.screenY/10, 500, "left")
		love.graphics.printf(":", 110, self.screenY - self.screenY/10 - 2, 500, "left")
		love.graphics.printf(secOutput, 125, self.screenY - self.screenY/10, 500, "left")	
          
          if playerControl then
               love.graphics.setFont(font_tut)
               currTime = love.timer.getTime()
               if (currTime - tutClock) < 3 then
                    local printString = 'save your master'
                    centWidth = love.graphics.getWidth()/2 - font_tut:getWidth(printString)/2
                    love.graphics.print(printString, centWidth, love.graphics.getHeight()*0.15)
               elseif (currTime - tutClock) < 6 then
                    printString = 'transfer life while you are close'
                    centWidth = love.graphics.getWidth()/2 - font_tut:getWidth(printString)/2
                    love.graphics.print(printString, centWidth, love.graphics.getHeight()*0.15)
               elseif (currTime - tutClock) < 9 then
                    printString = 'collect life in the Expanse'
                    centWidth = love.graphics.getWidth()/2 - font_tut:getWidth(printString)/2
                    love.graphics.print(printString, centWidth, love.graphics.getHeight()*0.15)
               elseif (currTime - tutClock) < 12 then
                    printString = 'avoid leeches and voids'
                    centWidth = love.graphics.getWidth()/2 - font_tut:getWidth(printString)/2
                    love.graphics.print(printString, centWidth, love.graphics.getHeight()*0.15)
               elseif (currTime - tutClock) < 15 then
                    printString = '"Spacebar" unleashes pulse'
                    centWidth = love.graphics.getWidth()/2 - font_tut:getWidth(printString)/2
                    love.graphics.print(printString, centWidth, love.graphics.getHeight()*0.15)
               elseif (currTime - tutClock) < 18 then
                    printString = 'good luck'
                    centWidth = love.graphics.getWidth()/2 - font_tut:getWidth(printString)/2
                    love.graphics.print(printString, centWidth, love.graphics.getHeight()*0.15)
               end
               love.graphics.setFont(orig_font)
          end

		 
        --ALWAYS draw player and eventhandler
		if gameOver == false then
			self.player:draw()
		end
        --love.graphics.setPixelEffect()
        self.eventHandler:draw()
        
end

function World:getMaxY()

        return self.height
        
end

function World:getMaxX()

        return self.width
        
end
function World:spawnParasites()

	math.randomseed(os.time())
	parasiteCount = 0
	while parasiteCount < self.totalParasites do
	         randXCoor = math.floor((math.random() * 100000)) % self.width
	         randYCoor = math.floor((math.random() * 100000)) % self.height
			  yNegOrPos = math.random(0,1)
			  if(xNegOrPos == 0) then
			         randXCoor = -randXCoor
			  end
			  if(yNegOrPos == 0) then
			         randYCoor = -randYCoor
			  end
			                        
			  --convert logical coordinates to actual coordinates
			  randXCoor = randXCoor - self.scrnXOffset + (self.screenX/2)
			  randYCoor = randYCoor - self.scrnYOffset + (self.screenY/2)
			  self.parasiteList[parasiteCount] = Parasite.load(randXCoor, randYCoor)
	         MyCollider.addParasiteCollider(randXCoor,randYCoor,parasiteCount)
			  parasiteCount = parasiteCount + 1
	end
end
function World:spawnCollectibles()
        currentCollectibles = 0
        math.randomseed(os.time())
        while currentCollectibles < self.totalCollectibles do
                
                correctSection = 0
                while correctSection == 0 do
                        --Generate random coordinates
                        randXCoor = math.floor((math.random() * 100000)) % self.width
                        randYCoor = math.floor((math.random() * 100000)) % self.height
                        
						
						
                        --coordinate system is messed up from playing around with the current program
                        --max width is 1500
                        --max height is 1400
                        --not sure this is mapping to 5000, 5000
                        --randXCoor = math.floor((math.random() * 100000)) % 1500
                        --randYCoor = math.floor((math.random() * 100000)) % 1400
                        
                        --randXCoor = math.random(-1500, 1500)
                        --randYCoor = math.random(-1400, 1400)
                        
                        --Calculate zone of generated coordinates
                        center = {(self.width/2), (self.height/2)}
                        distance = math.sqrt(((randXCoor - center[1]) ^ 2) + ((randYCoor - center[2]) ^ 2)) 
                        if distance < self.zoneEdges[1] then
                                currentZone = 1
                        end
                        if (distance >= self.zoneEdges[1]) and (distance < self.zoneEdges[2]) then
                                currentZone = 2
                        end
                        if (distance > self.zoneEdges[2]) and (distance < self.width) then
                                currentZone = 3
                        end
                        
                        --Calculate necessary zone
                        if currentCollectibles ~= 0 then
                                currentZonePercentages[1] = self.itemsInZones[1] / currentCollectibles
                                currentZonePercentages[2] = self.itemsInZones[2] / currentCollectibles
                                currentZonePercentages[3] = self.itemsInZones[3] / currentCollectibles
                        else
                                currentZonePercentages = {0, 0, 0}
                        end
                        
                        zoneDissonance = {0, 0, 0}
                        zoneDissonance[1] = self.zonePercentages[1] - currentZonePercentages[1]
                        zoneDissonance[2] = self.zonePercentages[2] - currentZonePercentages[2]
                        zoneDissonance[3] = self.zonePercentages[3] - currentZonePercentages[3]
                        
                        desiredZone = 1
                        if zoneDissonance[2] > zoneDissonance[1] then
                                desiredZone = 2
                        end
                        if zoneDissonance[3] > zoneDissonance[desiredZone] then
                                desiredZone = 3
                        end
                        
                        --Check to see if generated collectible is in desired zone
                        if currentZone == desiredZone then
                                correctSection = 1
                        end
                        
                        --Check to see if collectible is in borders
                        if (randXCoor < self.borderSize) or (randXCoor > (self.width - self.borderSize)) then
                                correctSection = 0
                        end
                        if (randYCoor < self.borderSize) or (randYCoor > (self.height - self.borderSize)) then
                                correctSection = 0
                        end
                        
                        if correctSection == 1 then
                                currentCollectibles = currentCollectibles + 1
								self.itemsInZones[desiredZone] = self.itemsInZones[desiredZone] + 1
                                --self.collectibleList[currentCollectibles] = Collectible.load({randXCoor, randYCoor}, "energy")
                                --not sure what this "energy" string is for, so leaving it out for now
                                --self.debugText = self.debugText..randXCoor..' '..randYCoor..'\n'
                                --code to make usre there are negative values since the range is x( -1500, 1500 ) and y( -1400, 1400 )
                                --[[xNegOrPos = math.random(0,1)
                                yNegOrPos = math.random(0,1)
                                if(xNegOrPos == 0) then
                                        randXCoor = -randXCoor
                                end
                                if(yNegOrPos == 0) then
                                        randYCoor = -randYCoor
                                end--]]
                        
								--convert logical coordinates to actual coordinates
								randXCoor = randXCoor - self.scrnXOffset + (self.screenX/2)
						randYCoor = randYCoor - self.scrnYOffset + (self.screenY/2)
						
                                
                                self.collectibleList[currentCollectibles] = Collectible.load(randXCoor, randYCoor)
                                MyCollider.addCollectibleCollider(randXCoor,randYCoor,currentCollectibles)
                                --self.collectibleList[currentCollectibles] = Collectible.load(100, 100)
                        end
                end
        end
end

function World:spawnStars()
        math.randomseed(os.time())
        
        currentStars = 0
        while currentStars < self.numStars do
                randXCoor = math.floor((math.random() * 100000)) % self.width
                randYCoor = math.floor((math.random() * 100000)) % self.height
                randLifetime = math.floor((math.random() * 100)) % 4
                randEmissionRate = math.random()
                
                currentStars = currentStars + 1
                self.starList[currentStars] = Star.load(randXCoor - self.scrnXOffset, randYCoor - self.scrnYOffset, 1 --[[randLifetime]], 1--[[randEmissionRate]])
        end
end

function World:spawnStaticStars()
        math.randomseed(os.time())
        
        curStars = 0
        while curStars < self.numStaticStars do
                randX = math.floor((math.random() * 100000)) % (self.width + self.screenX)
                randY = math.floor((math.random() * 100000)) % (self.height + self.screenY)
                
                curStars = curStars + 1
                self.staticStarList[curStars] = {randX - self.scrnXOffset, randY - self.scrnYOffset}
        end
end
                
function World.calcDist(x1, y1, x2, y2)

        dist = math.sqrt(((x1 - x2) ^ 2) + ((y1 - y2) ^ 2))
        return dist
        
end

function World:boundsCheck(x, y)

        if (x >= -400) and (x <= self.screenX + 400) and (y >= -400) and (y <= self.screenY + 400) then
                return true
        end
        
        return false
end
function World:playerCollidedWithGlow()

        self.debugText = self.debugText..'Player collided wih Glow'..'\n'
        
end


function World:playerCollidedWithCollectible(index)
        self.debugText = self.debugText..'Player collided wih collectible '..index..'\n'
		 self.collectibleList[index].particleSys:setColors(0, 0, 0, 0, 0, 0, 0, 0)
		 self.collectibleList[index].particleSys:stop()
		 self.player.health = self.player.health + 500
end
function World:playerCollidedWithParasite(index)
	
		
		
		y2 = self.parasiteList[index].y
		y1 = self.player.y
		x2 = self.parasiteList[index].x
		x1 = self.player.x
		
		yDiff = (y2 - y1)
		xDiff = (x2 - x1)
		
		if ((x2 - x1) == 0) then
			slope = 0
		else
			slope = yDiff / xDiff
		end
		
		--figure out amount to change y based on slope
	    if (slope > parasiteSpeed) then 
			slope = parasiteSpeed
		 end 
	
	    
		if( slope < -parasiteSpeed) then
			slope = -parasiteSpeed
		end
		
		
		--need to determine add or subtract 1
		if( x2 < x1) then
			newX = self.parasiteList[index].x + parasiteSpeed
			newY = self.parasiteList[index].y + slope
		else
			newX = self.parasiteList[index].x - parasiteSpeed
			newY = self.parasiteList[index].y - slope
		end
		 
		 
		--need to check distance once a certain distance stop moving
		distance = math.sqrt((yDiff * yDiff) + (xDiff * xDiff))
		if( distance > 40) then
			self.parasiteList[index].x = newX
			self.parasiteList[index].y = newY
		end
		 
			
end

function World:spawnBlackHoles()
	math.randomseed(os.time())

	currentBlackHoles = 0
	while currentBlackHoles < self.totalBlackHoles do
		randXCoor = (math.floor((math.random() * 100000)) % (self.width - 800)) + 400
		randYCoor = (math.floor((math.random() * 100000)) % (self.height - 800)) + 400
		
		tooClose = false
		
		
			randXCoor = randXCoor - self.scrnXOffset + (self.screenX/2)
			randYCoor = randYCoor - self.scrnYOffset + (self.screenY/2)
		
		--Check to see if it is too close to glow
		interGlowDist = self.calcDist(self.glow.x, self.glow.y, randXCoor, randYCoor)
		if interGlowDist <= 800 then
			tooClose = true
		end
		
		--Check to see if it is too close to any other black hole
		i = 0
		while i < currentBlackHoles do
			interBHDist = self.calcDist((self.blackHoleList[i+1]).x, (self.blackHoleList[i+1]).y, randXCoor, randYCoor)
			if interBHDist <= 1600 then
				tooClose = true
			end
			i = i + 1
		end
		
		if tooClose == false then
			currentBlackHoles = currentBlackHoles + 1
			self.blackHoleList[currentBlackHoles] = BlackHole.load(randXCoor,randYCoor)
		end
	end
end

function World:playerCollidedWithBlackHole()
	math.randomseed(os.time())
	randXCoor = math.floor((math.random() * 100000)) % self.width
    randYCoor = math.floor((math.random() * 100000)) % self.height
	
	BHTest = true
	
	deltaX = randXCoor - self.eventHandler.currentPos[1]
	deltaY = randYCoor - self.eventHandler.currentPos[2]
	
	self.eventHandler.currentPos[1] = randXCoor
	self.eventHandler.currentPos[2] = randYCoor
	
	for i, object in ipairs(self.swirlyList) do
        object.x = object.x - deltaX
		object.y = object.y - deltaY
    end
    for i, star in ipairs(self.starList) do
		star.x = star.x - deltaX
		star.y = star.y - deltaY
    end
    for i=1, #self.staticStarList do
        self.staticStarList[i][1] = self.staticStarList[i][1] - deltaX
		self.staticStarList[i][2] = self.staticStarList[i][2] - deltaY
    end
    for i, collectible in ipairs(self.collectibleList) do
        collectible.x = collectible.x - deltaX
		collectible.y = collectible.y - deltaY
    end
	for i, blackHole in ipairs(self.blackHoleList) do
		blackHole.x = blackHole.x - deltaX
		blackHole.y = blackHole.y - deltaY
	end
	for i, parasite in ipairs(self.parasiteList) do
		dist = self.calcDist(parasite.x, parasite.y, 600, 400)
		if dist < 400 then
			--code to kill parasites goes here
			parasite.particleSys:setColors(0, 0, 0, 0, 0, 0, 0, 0)
		    parasite.particleSys:stop()
					
			MyCollider.setParasiteToGhost(i)
		end
	end
    self.glow.x = self.glow.x - deltaX
	self.glow.y = self.glow.y - deltaY

end

function World:checkBlackHoles()

	for i, blackHole in ipairs(self.blackHoleList) do
		--Calculate distance between player and black hole
		dist = self.calcDist(blackHole.x, blackHole.y, 600, 400)
		testOutput = dist
		
		if dist < 50 then
			self:playerCollidedWithBlackHole()
			return
		end
		
		--If beyond edge, suck in
		if dist <= blackHole.radius then
			
			--Calculate direction for particles
			distX = blackHole.x - self.player.x
			distY = blackHole.y - self.player.y
			
			if (distX == 0) then
				BHslope = 0
			else
				BHslope = distY / distX
			end
			
			BHXPull = (((dist/400) - 1) * -16)
		
			--figure out amount to change y based on slope
			if (BHslope > BHXPull) then 
				BHslope = BHXPull
			end 
	
	    
			if( BHslope < -BHXPull) then
				BHslope = -BHXPull
			end
		
			--need to determine add or subtract 1
			if(distX > 0) then
				self.eventHandler.currentPos[1] = self.eventHandler.currentPos[1] + BHXPull
				self.eventHandler.currentPos[2] = self.eventHandler.currentPos[2] + BHslope
				
				for i, object in ipairs(self.swirlyList) do
					object.x = object.x - BHXPull
					object.y = object.y -  BHslope
				end
				for i, star in ipairs(self.starList) do
					star.x = star.x - BHXPull
					star.y = star.y - BHslope
				end
				for i=1, #self.staticStarList do
					self.staticStarList[i][1] = self.staticStarList[i][1] - BHXPull
					self.staticStarList[i][2] = self.staticStarList[i][2] - BHslope
				end
				for i, collectible in ipairs(self.collectibleList) do
					collectible.x = collectible.x - BHXPull
					collectible.y = collectible.y - BHslope
				end
				for i, blackHole in ipairs(self.blackHoleList) do
					blackHole.x = blackHole.x - BHXPull
					blackHole.y = blackHole.y - BHslope
				end
				self.glow.x = self.glow.x - BHXPull
				self.glow.y = self.glow.y - BHslope

			else

				for i, object in ipairs(self.swirlyList) do
					object.x = object.x + BHXPull
					object.y = object.y + BHslope
				end
				for i, star in ipairs(self.starList) do
					star.x = star.x + BHXPull
					star.y = star.y + BHslope
				end
				for i=1, #self.staticStarList do
					self.staticStarList[i][1] = self.staticStarList[i][1] + BHXPull
					self.staticStarList[i][2] = self.staticStarList[i][2] + BHslope
				end
				for i, collectible in ipairs(self.collectibleList) do
					collectible.x = collectible.x + BHXPull
					collectible.y = collectible.y + BHslope
				end
				for i, blackHole in ipairs(self.blackHoleList) do
					blackHole.x = blackHole.x + BHXPull
					blackHole.y = blackHole.y + BHslope
				end
				self.glow.x = self.glow.x + BHXPull
				self.glow.y = self.glow.y + BHslope
				
				self.eventHandler.currentPos[1] = self.eventHandler.currentPos[1] - BHXPull
				self.eventHandler.currentPos[2] = self.eventHandler.currentPos[2] -BHslope
			
			end
			
			toBH = 0

		end
	end
end